package com.yuyou.fn.settlement.service.impl;

import com.github.wens.mybatisplus.examples.Example;
import com.yuyou.fn.common.exception.BusException;
import org.springframework.stereotype.Service;

import com.yuyou.fn.settlement.mapper.ChangeRecordMapper;
import com.yuyou.fn.settlement.entity.ChangeRecord;
import com.yuyou.fn.settlement.service.IChangeRecordService;
import com.github.wens.framework.service.impl.SuperServiceImpl;

import java.util.Date;
import java.util.List;

/**
 *
 * ChangeRecord 表数据服务层接口实现类
 *
 */
@Service
public class ChangeRecordServiceImpl extends SuperServiceImpl<ChangeRecordMapper, ChangeRecord,Long> implements IChangeRecordService {


    @Override
    public List<ChangeRecord> findNotSettleChangeRecord(Long mainAccountId, String subject, Date start, Date end) {

        if(mainAccountId == null || subject == null ){
            throw new BusException("mainAccountId and subject is require");
        }

        Example<ChangeRecord> example = ChangeRecord.createExample();
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("mainAccountId",mainAccountId)
                .andEqualTo("subject",subject)
                .andEqualTo("direction",0)
                .andEqualTo("settleStatus" ,0 );

        if(start == null ){
            criteria.andGreaterThan("createTime",start);
        }
        if(end == null ){
            criteria.andLessThan("createTime" , end );
        }
        return findListByExample(example);

    }

    @Override
    public void updateSettleStatus(List<Long> changeRecordIdList, int settleStatus) {
        ChangeRecord changeRecord = new ChangeRecord();
        changeRecord.setSettleStatus(settleStatus);

        Example<ChangeRecord> example = ChangeRecord.createExample();
        example.createCriteria().andIn("changeRecordId" ,changeRecordIdList );

        updateSelectiveByExample(changeRecord,example);

    }
}